package cn.edu.nwsuaf.teachercenter.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import cn.edu.nwsuaf.teachercenter.model.PageModel;
import cn.edu.nwsuaf.teachercenter.pojo.ExamPaperInfo;
import cn.edu.nwsuaf.teachercenter.service.ExamPaperService;
import cn.edu.nwsuaf.teachercenter.utils.UniqueKeyUtils;

@Service(value="examPaperService")
public class ExamPaperServiceImpl extends BaseServiceImpl<ExamPaperInfo> implements ExamPaperService {

	@Override
	public String addExamPaper(ExamPaperInfo examPaperInfo) {
		// TODO Auto-generated method stub
		examPaperInfo.setExamPaperNo(UniqueKeyUtils.getUniqueCode());
		examPaperInfo.setExamPaperIscheck(0);
		super.saveData(examPaperInfo);
		return "success";
	}

	@Override
	public void loadExamPaper(String teacherNo, String p, ModelMap modelMap) {
		// TODO Auto-generated method stub
		PageModel<ExamPaperInfo> pageModel = new PageModel<>();
		String hql = "FROM ExamPaperInfo as exam where exam.teacher.teacherNo=?";
		String countHql = "SELECT COUNT(*) FROM ExamPaperInfo as exam where exam.teacher.teacherNo=?";
		String[] param = {teacherNo};
		int currentpage = 1;
		if(p!=null){
			currentpage = Integer.valueOf(p);
		}
		pageModel.setTotalrows(super.countData(countHql, param));
		pageModel.setCurrentpage(currentpage);
		pageModel.setList(super.findDataByHql(hql, param, currentpage, pageModel.getRows()));
		
		modelMap.addAttribute("pageModel",pageModel);
	}

}
